<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" type="text/css" href="../css/aui.css"/>
		<link rel="stylesheet" type="text/css" href="../icon/aosen/css/font-awesome.min.css" />
    <style>
    	body,html{
				background:white;
    	}
			.login-button{
					width: 14rem;
					height: 2.4rem;
					background: #e14104;
					text-align: center;
					line-height: 2.4rem;
					border-radius: 7px;
					margin: 0 auto;
					color: white
			}
    </style>
</head>
<body>
    <div style="margin-top:1rem">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-my"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入用户名/手机号" id="phoneNum">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label-icon">
                        <i class="aui-iconfont aui-icon-lock"></i>
                    </div>
                    <div class="aui-list-item-input">
                        <input type="password" placeholder="请输入密码" oninput="verifyPassword(this)" id="password">
                    </div>
                </div>
            </li>
        </ul>
    </div>
		<div class="" style="width:100%;margin-top:2rem">
				<div class="login-button" onclick="login()">登陆</div>
		</div>
		<div class="aui-row" style="width:100%;margin-top:2rem">
				<div class="aui-col-xs-6" style="text-align:left;padding-left:0.7rem">
						<span onclick="goToReset()">忘记密码？</span>
				</div>
				<div class="aui-col-xs-6" style="text-align:right;padding-right:0.7rem">
						<span onclick="goToRegister()">立即注册></span>
				</div>
		</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/request.js"></script>
<script type="text/javascript">
	apiready = function(){



	};
	function verifyPassword(tag){
			var han = /^[\u4e00-\u9fa5]+$/;
			if (han.test($api.val(tag))) {
          $api.val(tag,'');
      };
	}
	function goToRegister(){
			api.openWin({
					name: 'registPage',
					url: './win.html',
					pageParam: {
							page:'registPage',
							title: '注册'
					}
			});
	}
	function goToReset(){
			api.openWin({
					name: 'resetPage',
					url: './win.html',
					pageParam: {
							page:'resetPage',
							title: '重置密码',
							data:'forget'
					}
			});
	}
	function login(){
			var data = {};
			data['values'] = {};
			data['values']['phoneNum'] = $api.val($api.byId('phoneNum'));
			data['values']['password'] = $api.val($api.byId('password'));
			data['values']['deviceId'] = api.deviceId;
			requestData('Login/login',data,'NO','NO','NO',_callbackLogRelt);
	}
	function _callbackLogRelt(ret){
			if(ret.status == 200){
					api.toast({
							msg: ret.msg,
							duration: 3000,
							location: 'bottom'
					});
					$api.setStorage('userId', ret.userMsg['id']);
					$api.setStorage('userName', ret.userMsg['user_name']);
					$api.setStorage('userHeader', ret.userMsg['user_header']);
					$api.setStorage('userType', ret.userMsg['user_type']);
					getRongToken(ret.userMsg['id'],ret.userMsg['user_name'],ret.userMsg['user_header']);
					api.sendEvent({
					    name: 'reload',
					});

			}else{
					api.toast({
							msg: ret.msg,
							duration: 1000,
							location: 'bottom'
					});
			}
	}
	function getRongToken(userId,userName,userHeader){
    var data = {};
    data['values'] = {};
    data['values']['userId'] = userId;
    data['values']['userName'] = userName;
    data['values']['userHeader'] = userHeader;
    requestData('Chatroom/getToken',data,'YES','NO','NO',_callbackToken);
  }
	function _callbackToken(ret){
		if(ret.code == 200){
      $api.setStorage('rongToken', ret.token);

    }else{
      api.toast({
        msg: '获取token失败！请稍后再试',
        duration: 4000,
        location: 'bottom'
      });
    }
		setTimeout(function(){
				api.closeWin({});
		},1000);
	}
</script>
</html>
